/*
* Copyright (C) Microsoft. All rights reserved.  
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not 
* use this file except in compliance with the License.  You may obtain a copy 
* of the License at http://www.apache.org/licenses/LICENSE-2.0  
* 
* THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
* WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
* MERCHANTABLITY OR NON-INFRINGEMENT. 
*
* See the Apache License, Version 2.0 for specific language governing 
* permissions and limitations under the License.
*
*/
#pragma once

#include <journal/models/interfaces.h>
#include <journal/models/internal_interfaces.h>

namespace journal { namespace model {

namespace b = baja;
namespace s = baja::storage;

class photo_model_factory : public iphoto_model_factory
{
public:
    photo_model_factory(std::shared_ptr<s::iengine> dbEngine);
    static std::shared_ptr<iphoto_model_factory> create(std::shared_ptr<s::iengine> dbEngine);

    // iphoto_model_factory
    void getPersistedPhotoIds(b::uint32 pageId, std::vector<b::uint32>& ids);

    void removeFromDB(
            const b::uint32& pageId
            );

    std::shared_ptr<iphoto_model> createPhoto(
        const std::shared_ptr<ipage_model>& parent);

    std::shared_ptr<iphoto_model> recreatePhoto(
        const std::shared_ptr<ipage_model>& parent,
        const b::uint32& photoId);

    b::uint32 typeToken();

private:
    static b::uint32 _typeToken;
    b::uint32 _nextId;
    std::shared_ptr<s::iengine> _dbEngine;
    std::shared_ptr<journal::model::db::iphoto_table> _photoTable;
    std::shared_ptr<journal::model::db::imedia_file_table> _mediaFileTable;

    void disposeUnusedFiles();
};

std::shared_ptr<iphoto_model_factory> createPhotoModelFactory(std::shared_ptr<s::iengine> dbEngine);

}} // namespace journal::model